package GUI;

import CDB.Detalleventa;
import CDB.Stock;
import CDB.Ticket;
import CDB.Ventas;
import Negocios.ControlSales;
import Negocios.ControlSalesDetail;
import Negocios.ControlStock;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.beans.PropertyVetoException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import ticket.impresion.ControlTicket;
import ticket.impresion.ControlTicketNDB;

/**
 *
 * @author lightemp
 */
public class Devoluciones extends javax.swing.JInternalFrame {

    private JCheckBox[] chkHabilitaDevolucion;//Activa o desactiva una listSubcategorias
    private int numDetalles = 0;//Numero de supcategorias
    private JLabel[] lblIdDetalle;
    private JPanel jpnTitulos[];
    private JPanel jpnAcciones[];
    private Ventas venta;
    private String empleado;
    private String folio;
    private List<Ticket> lista;
    private int idVenta = 0;

    public Devoluciones(Ventas venta, String empleado, String folio) {
        initComponents();
        this.venta = venta;
        idVenta = venta.getIdventa();
        this.empleado = empleado;
        this.folio = folio;
        Dimension preferredSize = new Dimension(164, 500);
        jpnControles.setPreferredSize(preferredSize);
        //jpnDevoluciones.setPreferredSize(new Dimension(648, 500));
        cargaPanel();
    }

    private void cargaPanel() {
        //Prepara los paneles
        jpnDevoluciones.setVisible(false);
        jpnDevoluciones.removeAll();
        //Genera los campos para los precios
        cargaVenta(venta);
        //Muestra los cambios realizados
        jpnDevoluciones.setVisible(true);
    }

    //Establece la organizacion de los componentes de un panel
    private void organizaLayouts(JPanel panel) {
        panel.setLayout(new GridLayout(0, 1, 3, 3));
    }

    private void cargaVenta(Ventas venta) {
        int anchoItem = (jpnDevoluciones.getWidth() / 5);
        //-----------Detalles de Venta-----------------------
        //Obtengo los registros
        ControlSalesDetail csd = new ControlSalesDetail();
        List listDetalleVenta = null;
        try {
            listDetalleVenta = csd.selectByIdVenta(venta.getIdventa());
            int j = 0;
            lista = new ArrayList();
            while (j < listDetalleVenta.size()) {
                Detalleventa detalle = (Detalleventa) listDetalleVenta.get(j);
                Ticket ticket = new Ticket(
                        detalle.getProducto().getNombre().toString(),
                        detalle.getDetalleproducto().getCosto());
                lista.add(ticket);
                j++;
            }

        } catch (Exception e) {
            throw e;
        }

        numDetalles = listDetalleVenta.size();
        //Inicializo los componentes
        chkHabilitaDevolucion = new JCheckBox[numDetalles];

        JLabel lblTiClave[] = new JLabel[numDetalles];//Etiquetas con el nombre de producto
        JLabel lblTiNombre[] = new JLabel[numDetalles];//Etiquetas con el nombre de producto
        JLabel lblTiPrecio[] = new JLabel[numDetalles];//Etiquetas con el nombre de producto
        JLabel lblTiHabilita[] = new JLabel[numDetalles];//Etiquetas con el nombre de producto
        JLabel lblTiPresentacion[] = new JLabel[numDetalles];//Etiquetas con el nombre de producto
        jpnTitulos = new JPanel[numDetalles];//Paneles
        JPanel jpnContenedor[] = new JPanel[numDetalles];//Paneles

        lblIdDetalle = new JLabel[numDetalles];//Etiquetas con el id
        JLabel lblNombre[] = new JLabel[numDetalles];//Etiquetas con el nombre de producto
        JLabel lblPrecio[] = new JLabel[numDetalles];//Etiquetas con el precio de producto
        JLabel lblPresentacion[] = new JLabel[numDetalles];//Etiquetas con el precio de producto
        jpnAcciones = new JPanel[numDetalles];//Paneles
        //create new Font
        Font font = new Font("Arial", Font.ITALIC, 12);
        for (int i = 0; i < numDetalles; i++) {
            final int indice = i;
            Detalleventa detalle = (Detalleventa) listDetalleVenta.get(indice);
            detalle.getDetalleproducto().getTipo();
            //Propiedades CheckBox             
            chkHabilitaDevolucion[i] = new JCheckBox("Cancelar...");
            chkHabilitaDevolucion[i].setFont(font);
            chkHabilitaDevolucion[i].setForeground(Color.DARK_GRAY);
            chkHabilitaDevolucion[i].setSize(anchoItem, 14);
            chkHabilitaDevolucion[i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    actionPanel(evt, indice);
                }
            });
            //----------Propiedades Etiquetas
            lblIdDetalle[i] = new JLabel(detalle.getIddetalleventa().toString());
            lblIdDetalle[i].setFont(font);
            lblIdDetalle[i].setForeground(Color.DARK_GRAY);
            lblIdDetalle[i].setName(String.valueOf(detalle.getIddetalleventa()));
            lblIdDetalle[i].setSize(anchoItem, 14);
            //--------------TITULOS--------------------------------------

            lblTiClave[i] = new JLabel("Clave");
            lblTiClave[i].setFont(font);
            lblTiClave[i].setForeground(Color.white);
            lblTiClave[i].setSize(anchoItem, 14);

            lblTiNombre[i] = new JLabel("Nombre");
            lblTiNombre[i].setFont(font);
            lblTiNombre[i].setForeground(Color.white);
            lblTiNombre[i].setSize(anchoItem, 14);

            lblTiPresentacion[i] = new JLabel("Tipo");
            lblTiPresentacion[i].setFont(font);
            lblTiPresentacion[i].setForeground(Color.white);
            lblTiPresentacion[i].setSize(anchoItem, 14);

            lblTiPrecio[i] = new JLabel("Precio");
            lblTiPrecio[i].setFont(font);
            lblTiPrecio[i].setForeground(Color.white);
            lblTiPrecio[i].setSize(anchoItem, 14);

            lblTiHabilita[i] = new JLabel("Seleccionar");
            lblTiHabilita[i].setFont(font);
            lblTiHabilita[i].setForeground(Color.white);
            lblTiHabilita[i].setSize(anchoItem, 14);

            //---------------Panel Titulos-------------------------------
            jpnTitulos[i] = new JPanel();
            jpnTitulos[i].setBackground(new java.awt.Color(0, 150, 0));

            //------------------Panel contenedor de titulos y precios
            jpnContenedor[i] = new JPanel();

            jpnContenedor[i].setSize(jpnDevoluciones.getWidth(), 40);
            //----------------CELDAS-----------------------------

            lblNombre[i] = new JLabel(detalle.getProducto().getNombre());
            lblNombre[i].setFont(font);
            lblNombre[i].setForeground(Color.DARK_GRAY);
            lblNombre[i].setSize(anchoItem, 14);

            lblPresentacion[i] = new JLabel(detalle.getDetalleproducto().getTipo());
            lblPresentacion[i].setFont(font);
            lblPresentacion[i].setForeground(Color.DARK_GRAY);
            lblPresentacion[i].setSize(anchoItem, 14);

            lblPrecio[i] = new JLabel(String.valueOf(detalle.getDetalleproducto().getCosto()));
            lblPrecio[i].setFont(font);
            lblPrecio[i].setForeground(Color.DARK_GRAY);
            lblPrecio[i].setSize(anchoItem, 14);
            //---------Propiedades Panel
            jpnAcciones[i] = new JPanel();
            jpnAcciones[i].setBackground(Color.white);

            //LAYOUTS
            //Asigna organizacion
            jpnTitulos[i].setLayout(new GridLayout(1, 5));
            jpnAcciones[i].setLayout(new GridLayout(1, 5));
            organizaLayouts(jpnContenedor[i]);
            jpnDevoluciones.setLayout(new GridLayout(30, 1));

            //Colocando los objetos
            jpnTitulos[i].add(lblTiClave[i], BorderLayout.EAST);
            jpnTitulos[i].add(lblTiNombre[i], BorderLayout.CENTER);
            jpnTitulos[i].add(lblTiPresentacion[i], BorderLayout.WEST);
            jpnTitulos[i].add(lblTiPrecio[i], BorderLayout.WEST);
            jpnTitulos[i].add(lblTiHabilita[i], BorderLayout.WEST);
            jpnTitulos[i].setSize(jpnDevoluciones.getWidth(), 20);
            //Colocando los objetos
            jpnAcciones[i].add(lblIdDetalle[i], BorderLayout.EAST);
            jpnAcciones[i].add(lblNombre[i], BorderLayout.CENTER);
            jpnAcciones[i].add(lblPresentacion[i], BorderLayout.WEST);
            jpnAcciones[i].add(lblPrecio[i], BorderLayout.WEST);
            jpnAcciones[i].add(chkHabilitaDevolucion[i], BorderLayout.WEST);
            jpnAcciones[i].setSize(jpnDevoluciones.getWidth(), 20);

            jpnContenedor[i].add(jpnTitulos[i]);
            jpnContenedor[i].add(jpnAcciones[i]);

            jpnDevoluciones.add(jpnContenedor[i]);
        }
    }

    private void actionPanel(java.awt.event.MouseEvent evt, final int indice) {
        if (chkHabilitaDevolucion[indice].isSelected() == false) {
            jpnTitulos[indice].setBackground(new java.awt.Color(0, 150, 0));
            jpnAcciones[indice].setBackground(Color.white);
            chkHabilitaDevolucion[indice].setText("Cancelar...");
        }
        if (chkHabilitaDevolucion[indice].isSelected() == true) {
            jpnTitulos[indice].setBackground(new java.awt.Color(0, 150, 100));
            jpnAcciones[indice].setBackground(Color.lightGray);
            chkHabilitaDevolucion[indice].setText("Cancelado");
        }

    }

    private void restaurarStock(Stock stock, int consumo) {
        stock.setCantidad(stock.getCantidad() + consumo);
        ControlStock cst = new ControlStock();
        cst.Update(stock.getIdstock(),
                stock.getNombre(),
                stock.getCantidad(),
                stock.getMinimo(),
                stock.getPreciogranel(),
                stock.getProveedores());
    }

    private void restaurarVenta(Ventas venta, int costoProducto) {
        ControlSales cs = new ControlSales();
        cs.update(venta.getIdventa(), venta.getFecha(),
                venta.getEmpleados(),
                ((int) venta.getTotalventa() - costoProducto));
    }

    private void eliminaVenta(Detalleventa detalle) {
        ControlSales cs = new ControlSales();
        cs.delete(detalle);
        JOptionPane.showMessageDialog(this, "Devolucion realizada exitosamente", "Devoluciones", 2);
    }

    private void cancelaVenta(boolean elimVenta) {
        ControlSalesDetail csd = new ControlSalesDetail();
        Detalleventa detalle = null;
        //Reviso si quiere eliminar la venta completa
        if (elimVenta == false) {
            int numarray = 0;
            for (int i = 0; i < numDetalles; i++) {
                if (chkHabilitaDevolucion[i].isSelected()) {
                    //Obtiene el id del detalle
                    int idDetalle = Integer.parseInt(lblIdDetalle[i].getName());
                    detalle = (Detalleventa) csd.selectByIdDetalleVenta(idDetalle);
                    //Obtiene el consumo de stock
                    int consumo = detalle.getDetalleproducto().getConsumo();
                    //Repone el stock consumido
                    restaurarStock(detalle.getProducto().getStock(), consumo);
//                Recalcula el total de venta
                    restaurarVenta(detalle.getVentas(), (int) detalle.getDetalleproducto().getCosto());
                    numarray++;
                    if (numarray == numDetalles) {
                        i = numDetalles;
                        eliminaVenta(detalle);
                        btnDevolver.setEnabled(false);
                        btnCancelaVenta.setEnabled(false);
                    } else {
                        csd.delete(detalle);
                    }
                }

            }
            cargaPanel();
        } else {
            for (int i = 0; i < numDetalles; i++) {
                //Obtiene el id del detalle
                int idDetalle = Integer.parseInt(lblIdDetalle[i].getName());
                detalle = (Detalleventa) csd.selectByIdDetalleVenta(idDetalle);
                //Obtiene el consumo de stock
                int consumo = detalle.getDetalleproducto().getConsumo();
                //Repone el stock consumido
                restaurarStock(detalle.getProducto().getStock(), consumo);
//                Recalcula el total de venta
                restaurarVenta(detalle.getVentas(), (int) detalle.getDetalleproducto().getCosto());
            }
            eliminaVenta(detalle);
            btnDevolver.setEnabled(false);
            btnCancelaVenta.setEnabled(false);
        }
        cargaPanel();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jspScroll = new javax.swing.JScrollPane();
        jpnDevoluciones = new javax.swing.JPanel();
        jpnControles = new javax.swing.JPanel();
        btnDevolver = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnCancelaVenta = new javax.swing.JButton();
        lblEliminarVenta = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnImprimir = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setTitle("Sales Dispatcher - Devoluciones");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/IconosGenerales/delete.png"))); // NOI18N

        jspScroll.setBorder(javax.swing.BorderFactory.createTitledBorder("Lista de productos de la venta"));

        jpnDevoluciones.setBackground(new java.awt.Color(255, 255, 255));
        jpnDevoluciones.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jpnDevoluciones.setPreferredSize(new java.awt.Dimension(440, 1100));
        jpnDevoluciones.setRequestFocusEnabled(false);

        javax.swing.GroupLayout jpnDevolucionesLayout = new javax.swing.GroupLayout(jpnDevoluciones);
        jpnDevoluciones.setLayout(jpnDevolucionesLayout);
        jpnDevolucionesLayout.setHorizontalGroup(
            jpnDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 485, Short.MAX_VALUE)
        );
        jpnDevolucionesLayout.setVerticalGroup(
            jpnDevolucionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1094, Short.MAX_VALUE)
        );

        jspScroll.setViewportView(jpnDevoluciones);

        jpnControles.setBackground(java.awt.Color.gray);
        jpnControles.setPreferredSize(new java.awt.Dimension(164, 500));

        btnDevolver.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconosGenerales/apply.png"))); // NOI18N
        btnDevolver.setText("Devolver");
        btnDevolver.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnDevolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDevolverActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconosGenerales/Cancel.png"))); // NOI18N
        btnCancelar.setText("Salir");
        btnCancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconosGenerales/shopcart.png"))); // NOI18N

        btnCancelaVenta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconosGenerales/delete.png"))); // NOI18N
        btnCancelaVenta.setText("Eliminar");
        btnCancelaVenta.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnCancelaVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelaVentaActionPerformed(evt);
            }
        });

        lblEliminarVenta.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
        lblEliminarVenta.setForeground(java.awt.Color.white);
        lblEliminarVenta.setText("Venta completa:");

        jLabel3.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
        jLabel3.setForeground(java.awt.Color.white);
        jLabel3.setText("Productos:");

        btnImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IconosGenerales/printer.png"))); // NOI18N
        btnImprimir.setText("Imprimir");
        btnImprimir.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnControlesLayout = new javax.swing.GroupLayout(jpnControles);
        jpnControles.setLayout(jpnControlesLayout);
        jpnControlesLayout.setHorizontalGroup(
            jpnControlesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnControlesLayout.createSequentialGroup()
                .addGroup(jpnControlesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnControlesLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jpnControlesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel3)
                            .addComponent(lblEliminarVenta)))
                    .addGroup(jpnControlesLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1))
                    .addGroup(jpnControlesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jpnControlesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(btnCancelaVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnImprimir)
                            .addComponent(btnDevolver)
                            .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpnControlesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancelaVenta, btnCancelar, btnDevolver, btnImprimir, jLabel1, jLabel3, lblEliminarVenta});

        jpnControlesLayout.setVerticalGroup(
            jpnControlesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnControlesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDevolver, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblEliminarVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelaVenta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jpnControlesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel3, lblEliminarVenta});

        jpnControlesLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnCancelaVenta, btnCancelar, btnDevolver, btnImprimir});

        jLabel4.setBackground(new java.awt.Color(204, 204, 204));
        jLabel4.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
        jLabel4.setText("<html>Esta ventana permite quitar uno o varios productos de la lista, o cancelar totalmente la venta</html>");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 476, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jspScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jpnControles, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jspScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
            .addComponent(jpnControles, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDevolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDevolverActionPerformed
        cancelaVenta(false);
        JOptionPane.showMessageDialog(this, "Se ha hecho una devolucion correctamente!", "Devolución", 1);
    }//GEN-LAST:event_btnDevolverActionPerformed

    private void btnCancelaVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelaVentaActionPerformed
        cancelaVenta(true);
        JOptionPane.showMessageDialog(this, "Venta cancelada correctamente", "Cancelado", 1);
        try {
            this.setClosed(true);
            System.gc();
        } catch (PropertyVetoException ex) {
            this.dispose();
            System.gc();
        }
    }//GEN-LAST:event_btnCancelaVentaActionPerformed

    private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
        ControlTicketNDB ctrlTicket = new ControlTicketNDB(
                lista,
                empleado,
                folio);
    }//GEN-LAST:event_btnImprimirActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        try {
            this.setClosed(true);
            System.gc();
        } catch (PropertyVetoException ex) {
            this.dispose();
            System.gc();
        }
    }//GEN-LAST:event_btnCancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelaVenta;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnDevolver;
    private javax.swing.JButton btnImprimir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jpnControles;
    private javax.swing.JPanel jpnDevoluciones;
    private javax.swing.JScrollPane jspScroll;
    private javax.swing.JLabel lblEliminarVenta;
    // End of variables declaration//GEN-END:variables
}
